package cn.kgm.makeGodV2.ruleEngine;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-25 14:57
 * @Description: cn.kgm.makeGodV2.ruleEngine.CompleteRuleEngineTest
 */
public class CompleteRuleEngineTest {
    public static void main(String[] args) {
        SimpleRuleEngine ruleEngine = SimpleRuleEngine.getInstance();

        // 打印所有已注册的规则类型
        System.out.println("已注册的规则类型: " + ruleEngine.getRegisteredRuleTypes());

        // 创建玩家数据
        Map<String, Integer> playerItems = new HashMap<>();
        playerItems.put("避毒丹", 2);
        playerItems.put("飞行符", 1);
        playerItems.put("疗伤药", 5);
        playerItems.put("灵石", 1000);

        // 测试1: 直接执行逻辑操作符规则
        System.out.println("\n=== 测试1: 直接执行OR规则 ===");
        ConditionConfig orCondition = ConditionConfig.and(
                ConditionConfig.atomic("SINGLE_ITEM_CHECK", Collections.singletonMap("避毒丹", 2)),
                ConditionConfig.atomic("SINGLE_ITEM_CHECK", Collections.singletonMap("飞行符", 1))
        );

        RuleContext context = new RuleContext();
        context.setParam("playerItems", playerItems);
        context.setParam("conditionConfig", orCondition);

        RuleResult<Boolean> orResult = ruleEngine.executeRule("OR", context);
        System.out.println("OR规则结果: " + orResult.getMessage());
        System.out.println("满足条件: " + orResult.getData());

        // 测试2: 使用executeComplexCondition执行复杂条件
        System.out.println("\n=== 测试2: 使用executeComplexCondition ===");
        ConditionConfig complexCondition = ConditionConfig.and(
                ConditionConfig.atomic("REALM_CHECK", "金丹期"),
                ConditionConfig.or(
                        ConditionConfig.atomic("SINGLE_ITEM_CHECK", Collections.singletonMap("避毒丹", 2)),
                        ConditionConfig.atomic("SINGLE_ITEM_CHECK", Collections.singletonMap("飞行符", 1))
                ),
                ConditionConfig.not(
                        ConditionConfig.atomic("SINGLE_ITEM_CHECK", Collections.singletonMap("灵石", 500))
                )
        );

        RuleContext context2 = new RuleContext();
        context2.setParam("playerRealm", "元婴期");
        context2.setParam("playerItems", playerItems);

        RuleResult<Boolean> complexResult = ruleEngine.executeComplexCondition(complexCondition, context2);
        System.out.println("复杂条件结果: " + complexResult.getMessage());
        System.out.println("满足条件: " + complexResult.getData());

        // 测试3: 单独执行原子规则
        System.out.println("\n=== 测试3: 单独执行原子规则 ===");
        RuleContext context3 = new RuleContext();
        context3.setParam("playerRealm", "元婴期");
        context3.setParam("requiredRealm", "金丹期");

        RuleResult<Boolean> realmResult = ruleEngine.executeRule("REALM_CHECK", context3);
        System.out.println("境界检查结果: " + realmResult.getMessage());
    }
}
